#include<bits/stdc++.h>
using namespace std;
unordered_map<string, int> mapper;
unordered_map<int, string> reverseMapper;
bool vis[30];
bool grid[30][30];
int a, b, k;
int n, m;
void warshall() {
  for(int h=0; h<n; ++h) {
    for(int i=0; i<n; ++i)
      for(int j=0; j<n; ++j)
        grid[i][j] |= grid[i][h] & grid[h][j];
      }
}
void reset() {
  memset(grid, 0, sizeof grid);
  memset(vis, 0, sizeof vis);
  for(int i=0; i<n; ++i)
    grid[i][i] = true;
  mapper.clear();reverseMapper.clear();
  a=b=k=0;
}
int main() {
  string f, t;
  int tc=0;
  while(cin>>n>>m) {
    reset();
    if(!n) return 0;
    for(int i=0; i<m; ++i) {
      cin>>f>>t;
      if(mapper.count(f)==0) {
        a = k++;
        mapper[f] = a;
        reverseMapper[a] = f;
      }
      else {
        a = mapper[f];
      }
      if(mapper.count(t)==0) {
        b = k++;
        mapper[t] = b;
        reverseMapper[b] = t;
      }
      else {
        b = mapper[t];
      }
      grid[a][b] = true;
    }
    warshall();
    cout<<"Calling circles for data set "<<++tc<<":\n";
    for(int i=0;i<n;i++){
        if(vis[i]) continue;
        cout<<reverseMapper[i];
        for(int j=i+1;j<n;j++){
            if(vis[j]) continue;
            if(grid[i][j]&&grid[j][i]){
                vis[j]=true;
                cout << ", " <<reverseMapper[j];
            }
        }cout<<endl;
    }
  }
  return 0;
}
